//浮动参数
$(function(){
    $("#ROK").click(function(){
        var selectedLength=$(":checkbox[name='inlineCheckbox']:checked").length;
        if (selectedLength >= 0) {
            if(selectedLength !== 4){
                alert("请选择4项");
                exit();
            }

            var elements=document.getElementsByName("inlineCheckbox");
            for(i=0;i<elements.length;i++){
                var contextValue=document.getElementById("R1"+i);
                // console.log(contextValue)
                if(elements[i].checked===true){
                    console.log("inlineCheckbox"+i+"checked");
                    $("#R1"+i).show();
                }else{
                    console.log("inlineCheckbox"+i+"not  checked");
                    $("#R1"+i).hide();
                }
            }
        }
    })
})

//视频
var URL = window.URL || window.webkitURL; // 获取到window.URL对象
navigator.getUserMedia({
    video: true
}, function (stream) {
    // video.srcObject = stream;
    video2.srcObject = stream;
    video3.srcObject = stream;
    // console.log(video.srcObject)
}, function (error) {
    console.log(error.name || error);
});

//进度条
$(window).ready(function jindu($) {
    var $box = $('#box_');
    var $bg = $('#bg_');
    var $bgcolor = $('#bgcolor_');
    var $btn = $('#bt_');
    var $text = $('#text_xa_');
    var statu = false;
    var ox = 0;
    var lx = 0;
    var left = 100;
    var bgleft = 0;
    $btn.mousedown(function(e) {
        lx = $btn.offset().left;
        ox = e.pageX - left;
        statu = true;
    });
    $(document).mouseup(function() {
        statu = false;
    });
    $box.mousemove(function(e) {
        if (statu) {
            left = e.pageX - ox;
            if (left < 0) {
                left = 0;
            }
            if (left > 400) {
                left = 400;
            }
            $btn.css('left', left);
            $bgcolor.width(left);
            $text.html('' + parseFloat(left / 4).toFixed(0) + '%');
        }
    });
    $bg.click(function(e) {
        if (!statu) {
            bgleft = $bg.offset().left;
            left = e.pageX - bgleft;
            if (left < 0) {
                left = 0;
            }
            if (left > 400) {
                left = 400;
            }
            $btn.css('left', left);
            $bgcolor.stop().animate({
                width: left
            }, 200);
            $text.html('' + parseFloat(left / 4).toFixed(0) + '%');
        }
    });
})

//权限判断
// console.log($("#roleIdVal").text());
var roleId=$("#roleIdVal").text();
if(roleId>=3){
    $("a[name='adminShow']").attr("href","#");
    $("div[name='adminShow']").css("display","none");
}else if(roleId==2){
    $("a[name='adminShow']").attr("href","#");
}

//AI----xl
 window.setInterval(function () {
    cameraPic();
 },15000)

function cameraPic(){
    // console.log("heeee")
    $.ajax({
        url:"imgmessage",
        success:function (data){
            // console.log(data);
            if(data!="nodata"){
                // alert("有裂痕");
                console.log(data);
                var imgCanvs=document.getElementById("imgCanvs");
                imgCanvs.setAttribute("src",data);
                $("#modalShow").click();
            }
        },
        complete: function (XHR, TS) { XHR = null }
    });
}